//-----------------------------------------------------------------------------
#include <QKeyEvent>
#include <QtDebug>
#include "CMainFrm.h"
//-----------------------------------------------------------------------------
CMainFrm::CMainFrm(QWidget *parent) : QDialog(parent), currentValue() {
    setupUi(this);
}
//-----------------------------------------------------------------------------
void CMainFrm::keyReleaseEvent(QKeyEvent *event) {
	qDebug() << event->key();

    switch(event->key()) {
        case Qt::Key_0:
        case Qt::Key_1:
        case Qt::Key_2:
        case Qt::Key_3:
        case Qt::Key_4:
        case Qt::Key_5:
        case Qt::Key_6:
        case Qt::Key_7:
        case Qt::Key_8:
        case Qt::Key_9:
			if(currentValue.hasDecimaux()) {
				currentValue.addDecimal(event->key() - Qt::Key_0);
			}else {
				currentValue.addEntier(event->key() - Qt::Key_0);
			}
            wdScreen->setCurrentNumber(currentValue);
			qDebug() << currentValue.toDouble();
           	break;
        case Qt::Key_Colon:
        case Qt::Key_Semicolon:
			if(currentValue.hasDecimaux()) {
            	wdScreen->push(currentValue);
			}else {
				currentValue.beginDecimaux();
			}
            break;
        case Qt::Key_Return:
        case Qt::Key_Enter:
            wdScreen->push(currentValue);
        case Qt::Key_Escape:
			currentValue = CMyDouble();
            wdScreen->setCurrentNumber(currentValue);
			break;
        default:
            break;
    }
}
//-----------------------------------------------------------------------------
void CMainFrm::on_cmdSwap_clicked(bool) {
    wdScreen->swap();
}
//-----------------------------------------------------------------------------
void CMainFrm::on_cmdDelete_clicked(bool) {
    wdScreen->pop();
}
//-----------------------------------------------------------------------------
void CMainFrm::on_cmdClear_clicked(bool) {
    wdScreen->clear();
}
//-----------------------------------------------------------------------------
